local dbg = require 'jass.debug'
local jass = require 'jass.common'

local class = { }
setmetatable(class,class)
ac.selector.class['player'] = class

-- 选择
class.foreach = function(self,info)
    for i = 1,16 do 
        local u = ac.player(i)
        if u and self:do_filter(u) then 

            local enum = true 

            if enum and self._online then
                enum = u:is_online()
            end 

            if enum and self._team then 
                enum = self._team == u.team
            end 

            if enum then 
                table.insert(info,u)
            end 
        end
    end 
    return info 
end

local mt = { }
class.__index = mt 
extends(ac.selector)(mt)

-- 在线
function mt:online()
    self._online = true
    return self
end 

-- 队伍要求
function mt:team(name)
    self._team = name
    return self
end 

-- 是敌人
function mt:enemy(target)
    return self:filter(function(dest)
        return dest:is_enemy(target)
    end)
end 

-- 是友军
function mt:ally(target)
    return self:filter(function(dest)
        return dest:is_ally(target)
    end)
end 

-- 选取
function mt:select()
    return class.foreach(self, {})
end 

return class 